import time
from selenium.webdriver.common.by import By
from selenium import webdriver
import pytest
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
class TestBuer:
    @pytest.fixture(scope='function',name='driver')
    def setup_teardown(self):
        self.driver = webdriver.Chrome()
        self.driver.get("http://jxc.b2zg.cn/#/login")
        self.driver.implicitly_wait(15)
        self.driver.maximize_window()
        yield self.driver
        self.driver.quit()
    @pytest.fixture(scope='function')
    def tiyan(self,driver):
        # 点击体验一下
        WebDriverWait(self.driver, 10, 0.5).until(
            EC.presence_of_element_located((By.XPATH, "//*[text()='体验一下']"))).click()
        # 点击库存
        WebDriverWait(self.driver, 10, 0.5).until(
            EC.presence_of_element_located((By.XPATH, "//*[text()='库存']"))).click()
        # 点击盘点
        time.sleep(2)
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME, "text")))[0].click()
        yield self.driver

    """
    pytest框架是没有__init__方法的
    """
    def test_1(self,driver,tiyan):
        # 点击单据勾选框
        time.sleep(1)
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,"vxe-checkbox--icon")))[-1].click()
        # 点击复制按钮
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,"el-button")))[15].click()
        # 点击跳转页面的保存
        time.sleep(2)
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located((By.XPATH,"//*[text()='保存']"))).click()
        # 点击盘点
        time.sleep(2)
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,"tags-view-item")))[1].click()
        # 刷新页面
        self.driver.refresh()
        # 获取第一个tr
        time.sleep(2)
        TR = self.driver.find_elements(By.CLASS_NAME,"vxe-body--row")[0]
        # 获取tr下的td
        td = TR.find_elements(By.TAG_NAME,'td')[4]
        # 根据td下去查他的class name是不是未审核状态
        text = td.find_element(By.CLASS_NAME,"vxe-cell--label").text
        assert text == "未审核"
    def test_2(self,driver,tiyan):
        # 获取第一个tr
        time.sleep(2)
        TR = self.driver.find_elements(By.CLASS_NAME, "vxe-body--row")[0]
        # 获取tr下的td
        td = TR.find_elements(By.TAG_NAME, 'td')[4]
        # 根据td下去查他的class name是不是未审核状态
        text = td.find_element(By.CLASS_NAME, "vxe-cell--label").text
        assert text == "未审核"
        # 点击第一个单据复选框
        time.sleep(2)
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,"vxe-checkbox--icon")))[1].click()
        # 点击审核按钮  13
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located((By.XPATH,"//*[@id='app']/div/div[2]/section/div[2]/div[1]/div[1]/div[2]/div/button"))).click()
        # 获取第一个tr
        time.sleep(3)
        TR = self.driver.find_elements(By.CLASS_NAME, "vxe-body--row")[0]
        # 获取tr下的td
        td = TR.find_elements(By.TAG_NAME, 'td')[4]
        # 根据td下去查他的class name是不是未审核状态
        text = td.find_element(By.CLASS_NAME, "vxe-cell--label").text
        assert text == "已审核"

"""
生成测试报告：
pytest .\\06-pytest-html生成测试报告.py --html=report.html

"""